package com.itmuch.demoprovider;

import com.itmuch.demoprovider.feign.UserFeignClient;
import com.itmuch.demoprovider.feign.UserLoginDTO;
import com.itmuch.demoprovider.feign.UserSearchDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * xxx
 * corePoolSize=5, maxiumPoolSize=10, queue=5
 */
@RestController
public class UserController {
    @Autowired
    UserFeignClient userFeignClient;

    /**
     * 监控：错误率、错误次数
     * 5s内， 50%   20次
     */
    @GetMapping("login")
    public List<UserSearchDTO> login() {
        UserLoginDTO zhangsan = UserLoginDTO.builder()
            .username("zhangsan")
            .password("123123")
            .build();
        UserLoginDTO userLoginDTO = this.userFeignClient.login(zhangsan);

        String username = userLoginDTO.getUsername();

        return this.userFeignClient.getUserInfo(username, (short) 0);
    }

    public void test() {
        try {
            /**
             * 做监控
             * 1. 最近1min中的平均超时，如果平均超时时间，超过配置的阈值，就抛异常
             * 2. 监控最近的QPS
             * 3. 监控，错误率/次数
             */
            // monitor();

            // 业务上被保护的代码

        } catch (Exception e) {

        }
    }
}
